package com.example.demo.controller;

import com.example.demo.domain.dto.ResultDTO;
import com.example.demo.domain.vo.BorrowVO;
import com.example.demo.services.BorrowServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/borrow")
public class BorrowController {
    @Autowired
    BorrowServices borrowServices;
    ResultDTO resultDTO = new ResultDTO();

    @GetMapping("/listAllBorrowed")
    public ResultDTO listAllBorrowed() {
        List<BorrowVO> list = borrowServices.listAllBorrowList();
        resultDTO.setData(list);
        resultDTO.setMessage("已检索出所有借阅的书籍！");
        return resultDTO;
    }

    @GetMapping("/listBorrowed")
    public ResultDTO listBorrowed(int id) {
        List<BorrowVO> list = borrowServices.listAllBorrowByUserId(id);
        resultDTO.setData(list);
        resultDTO.setMessage("已检索出所有借阅的书籍！");
        return resultDTO;
    }

}
